package com.doit.demo02;

import java.io.*;
import java.net.Socket;

public class File_Client {
    public static void main(String[] args) throws IOException {
        BufferedInputStream bi = new BufferedInputStream(new FileInputStream("C:\\Users\\DHG\\Desktop\\2021.5.22.jpg"));
        Socket socket = new Socket("localhost", 6666);
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

        byte[] b = new byte[1024 * 8];
        int len;
        while ((len=bi.read(b))!=-1){
            bos.write(b,0 ,len );
        }

        socket.shutdownInput();
        System.out.println("文件传送完毕");

        //读取传回的数据
        InputStream in = socket.getInputStream();
        byte[] back = new byte[1024];
        in.read(back);
        System.out.println(new String(back));
        in.close();

        socket.close();
        bi.close();
    }
}
